package Atop100.huisu;

public class Class79 {


    public boolean exist(char[][] board, String word) {
        if(word.length()==0){
            return  false;
        }
        char[] words=word.toCharArray();
        int m=board.length;
        int n=board[0].length;
        for(int i=0;i<m;i++){
            for(int j=0;j<n;j++){
                if(backtracking(board,words,i,j,0)){
                    return true;
                }
            }
        }
        return  false;
    }



    public boolean backtracking(char[][]board,char[] word,int i,int j ,int k){
        if(i<0||i>board.length||j<0||j>board[0].length||board[i][j]==' '||board[i][j]!=word[k]){
            return false;
        }
        if(k==word.length){
            return true;
        }
        boolean res;
        board[i][j]=' ';
        res=backtracking(board,word,i+1,j,k+1)||backtracking(board,word,i-1,j,k+1)||backtracking(board,word,i,j+1,k+1)||backtracking(board,word,i,j-1,k+1);
        board[i][j]=word[k];
        return  res;
    }



    public static void main(String[] args) {
        String s="";
        String s1=" ";
        System.out.println(s.equals(s1));
        System.out.println(s.equals(null));
        System.out.println(s1.equals(null));
    }

}
